package com.horsen.service.base.exception;

import com.horsen.common.util.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 自定义异常
 *
 * @author Horsen
 */

@Data
@EqualsAndHashCode(callSuper = true)
public class HseduException extends RuntimeException {
    private Integer code;

    /**
     * 方式一 接收状态码和消息
     *
     * @param code    状态码
     * @param message 消息
     */
    public HseduException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    /**
     * 方式二 接收返回码枚举对象
     *
     * @param resultCodeEnum 返回码枚举对象
     */
    public HseduException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "HseduException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
